package edu.whu.puppygo.controller;

import edu.whu.puppygo.base.HttpResponse;
import edu.whu.puppygo.dao.GrowthRecordDao;
import edu.whu.puppygo.dto.GrowthRecordDto;
import edu.whu.puppygo.entity.GrowthRecord;
import edu.whu.puppygo.service.GrowthRecordService;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author guanruwang
 * @date 2023/12/2$
 */
@RestController
@RequestMapping("/growthRecord")
public class GrowthRecordController {

    @Resource
    private GrowthRecordDao growthRecordDao;

    @Resource
    private GrowthRecordService growthRecordService;

    @GetMapping("{petId}/{month}")
    public HttpResponse<List<GrowthRecord>> getGrowthRecord(@PathVariable long petId, @PathVariable int month, int pageNum, int pageSize) {
        Pageable pageable = PageRequest.of(pageNum, pageSize);
        List<GrowthRecord> records = growthRecordDao.findByPetIdAndRecordMonth(petId, month, pageable);
        return HttpResponse.success(records);
    }

    @PostMapping("")
    public HttpResponse<GrowthRecord> addGrowthRecord(@RequestBody GrowthRecordDto growthRecordDto) {
        GrowthRecord record = growthRecordService.addGrowthRecord(growthRecordDto);
        return HttpResponse.success(record);
    }

    @GetMapping("today")
    public HttpResponse<List<GrowthRecord>> getTodayGrowthRecord(long petId, int recordMonth, int recordDay) {
        List<GrowthRecord> records = growthRecordDao.findByPetIdAndRecordMonthAndRecordDay(petId, recordMonth, recordDay);
        return HttpResponse.success(records);
    }

}
